﻿//Copyright (c) 2010 William Liu, Enoch Ye
//William Liu <william.lyz@gmail.com>
//Enoch Ye <moonlight.enoch@gmail.com>

//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at

//       http://www.apache.org/licenses/LICENSE-2.0

//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using GBG_DBM.UI;
using GBG_DBM.Encryption;
using GBG_DBM.Reporting.Report_by_Product;
using GBG_DBM.Database;

namespace GBG_DBM.Test
{
    public partial class TestPanel : Form
    {

        #region glass panel test

        //[StructLayout(LayoutKind.Sequential)]
        //public struct MARGINS
        //{
        //    public int Left;
        //    public int Right;
        //    public int Top;
        //    public int Bottom;
        //}

        //[DllImport("dwmapi.dll", PreserveSig = false)]
        //public static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);

        //[DllImport("dwmapi.dll", PreserveSig = false)]
        //public static extern bool DwmIsCompositionEnabled();

        //protected override void OnLoad(EventArgs e)
        //{
        //    if (DwmIsCompositionEnabled())
        //    {
        //        MARGINS margin = new MARGINS();
        //        margin.Right = margin.Left = margin.Bottom = margin.Top = -1;
        //        DwmExtendFrameIntoClientArea(this.Handle, ref margin);
        //    }
        //    base.OnLoad(e);
        //}

        //protected override void OnPaintBackground(PaintEventArgs e)
        //{
        //    base.OnPaintBackground(e);
        //    if (DwmIsCompositionEnabled())
        //    {
        //        e.Graphics.Clear(Color.Black);
        //    }
        //}

        #endregion

        public TestPanel()
        {
            InitializeComponent();
        }

        private void Run_Login_TestPanel_Click(object sender, EventArgs e)
        {
            login_UI login = new login_UI();
            login.Show();
        }

        private void Run_Main_TestPanel_Click(object sender, EventArgs e)
        {
            Main_UI main_ui = new Main_UI();
            main_ui.Show();
        }

        private void Run_Currency_TestPanel_Click(object sender, EventArgs e)
        {
            //Run_Currency_TestPanel.Enabled = false;
            //Currency_UI currency = new Currency_UI();
           // currency.Show();
            ReportbyProduct _reportbyproduct = new ReportbyProduct();
            _reportbyproduct.Show();
        }

        private void Run_Freight_TestPanel_Click(object sender, EventArgs e)
        {
            Freight_UI freight = new Freight_UI();
            freight.Show();
        }

        private void Run_Setting_TestPanel_Click(object sender, EventArgs e)
        {
            Setting_UI setting = new Setting_UI();
            setting.Show();
        }

        private void Run_About_TestPanel_Click(object sender, EventArgs e)
        {
            About_UI about = new About_UI();
            about.Show();
        }

        private void Run_AddIngredient_TestPanel_Click(object sender, EventArgs e)
        {
            //AddIngredient_UI adding = new AddIngredient_UI();
            //adding.Show();
        }

        private void Run_Package_TestPanel_Click(object sender, EventArgs e)
        {
            Package_UI package = new Package_UI();
            package.Show();
        }

        private void Run_RawMetSup_TestPanel_Click(object sender, EventArgs e)
        {
            RawMaterialSupplier_UI rawmetsup = new RawMaterialSupplier_UI();
            rawmetsup.Show();
        }

        private void Run_Sup_RM_TestPanel_Click(object sender, EventArgs e)
        {
            Supplier_RM_UI suprm = new Supplier_RM_UI();
            suprm.Show();
        }

        private void Run_Sup_RM_View_TestPanel_Click(object sender, EventArgs e)
        {
            Supplier_RM_View_UI suprmview = new Supplier_RM_View_UI();
            suprmview.Show();
        }

        private void Run_Manu_Spec_TestPanel_Click(object sender, EventArgs e)
        {
            Manufacturing_Specification_UI manu_spec = new Manufacturing_Specification_UI();
            manu_spec.Show();
        }

        private void Run_Procuct_TestPanel_Click(object sender, EventArgs e)
        {
            Product_Details_UI product_d = new Product_Details_UI();
            product_d.Show();
        }

        private void Run_Product_Spec_TestPanel_Click(object sender, EventArgs e)
        {
            Product_Specifications_UI product_spec = new Product_Specifications_UI();
            product_spec.Show();
        }

        private void Run_Product_UI_TestPanel_Click(object sender, EventArgs e)
        {
            Product_UI product = new Product_UI();
            product.Show();
        }

        private void Run_STD_TestPanel_Click(object sender, EventArgs e)
        {
            STD_UI std = new STD_UI();
            std.Show();
        }

        private void Encryt_TestPanel_Click(object sender, EventArgs e)
        {
            string _orgTxt = "This string is waiting for encryption";
            string _encryptedTxt;
            string _uncryptedTxt;
            byte[] _keys = { 0x77, 0x30, 0x14, 0x15, 0x08, 0x09, 0xAF, 0xDF };

            _encryptedTxt = Encrypt.EncryptDES(_orgTxt, GlobalParameters.GlobalParams.EncryptKey);
            _uncryptedTxt = Encrypt.DecryptDES(_encryptedTxt, GlobalParameters.GlobalParams.EncryptKey);
            string _connStr = GBG_DBM.Properties.Settings.Default.DatabaseConnectionString;
            string _uncryconnStr = Encrypt.DecryptDES(_connStr, GlobalParameters.GlobalParams.EncryptKey);
            MessageBox.Show(_encryptedTxt + "\nUnEncrypt:" + _uncryptedTxt + "\nConnStr" + _uncryconnStr, "MSG",
                MessageBoxButtons.OK);
        }

        private void TestPanel_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“gBDataSet.CUR_EXCH”中。您可以根据需要移动或删除它。
            this.cUR_EXCHTableAdapter.Fill(this.gBDataSet.CUR_EXCH);

        }

        #region db test

        private void button1_Click(object sender, EventArgs e)
        {
            string _curcode;
            //double _nzd;
            decimal _nzd;

            _curcode = DBtestCURCode.Text;
            _nzd = Convert.ToDecimal(NZD.Text);

            this.Validate();
            this.cUREXCHBindingSource.EndEdit();
            this.cUR_EXCHTableAdapter.Insert(_curcode, _nzd);
            this.cUR_EXCHTableAdapter.Fill(this.gBDataSet.CUR_EXCH);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.cUREXCHBindingSource.EndEdit();
            this.cUR_EXCHTableAdapter.Update(this.gBDataSet.CUR_EXCH);
            this.cUR_EXCHTableAdapter.Fill(this.gBDataSet.CUR_EXCH);
        }
        #endregion

        
    }
}
